<%--
  Created by IntelliJ IDEA.
  User: nihaowzy
  Date: 2020/12/22
  Time: 15:06
  
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"  language="java" %>
<html>
  <head>
    <title>员工登录界面</title>
    <link rel="stylesheet" href="resource/layui/css/layui.css">
  </head>
  <body>
<!--  登录界面-->
  <h1 style="font-size: 50px; text-align: center">员工登录界面</h1>
  <hr/>
  <div class="layui-container">
    <form class="layui-form layui-form-pane">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-inline">
            <input  class="layui-input" lay-verify="required" lay-verType="tips" lay-reqText="用户名不能为空" type="text" name="username" placeholder="请输入用户名">
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-inline">
            <input class="layui-input" lay-verify="required" lay-verType="tips" lay-reqText="密码不能为空" type="text" name="password" placeholder="请输入密码">
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-inline">
          <div class="layui-input-inline">
            <input class="layui-input" lay-verify="required" lay-verType="tips" lay-reqText="验证码不能为空" type="text" name="checkCode" placeholder="请输入验证码">
          </div>
          <img id="checkCodeImg" src="checkCode.do" />
        </div>
      </div>
      <button class="layui-btn layui-btn-primary" type="button" lay-submit lay-filter="subBtnFilter">登录</button>
    </form>

  </div>


  <script src="resource/layui/layui.js"></script>
  <script>
    layui.use(['form','jquery','layer','table'],function () {
      let form = layui.form;
      let $ = layui.jquery;
      let layer = layui.layer;
      let table = layui.table;
      /**
       * 表单的提交
       */
      form.on("submit(subBtnFilter)",function (d) {
        let formData = d.field;
        //console.log(formData)
        $.post("user.do?service=login", formData,function (rs) {
            //登录失败，登录失败原因
          console.log("rs====="+rs);
          console.log(rs.code);
          console.log(rs.msg);
          console.log(rs.data);
          if(rs.code !=200){
            //展示失败原因
            layer.msg(rs.msg);
            return false;
          }
          //登陆成功跳转到用户列表界面
          location.href = "page.do?service=main";
        });
        //阻止默认提交事件
        return false;
      });

      $("#checkCodeImg").click(function () {
         $(this).attr("src","checkCode.do?"+new Date())
      })
    })
  </script>
  </body>
</html>
